const joi = require("joi");

const validate = (schema) => {
  return (req, res, next) => {
    const { error } = joi.object(schema).validate(req.body);
    if (error) {
      next(error);
    } else {
      next();
    }
  };
};

module.exports = validate;
